<template>
  <el-form :model="registerform" label-width="auto" style="max-width: 600px">
    <el-form-item label="用户名" prop="username">
      <el-input v-model="registerform.username" />
    </el-form-item>

    <el-form-item label="密码" prop="password">
      <el-input v-model="registerform.password" />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onRegister" style="width: 100%; height: 40px;">注册</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import {ElMessage} from "element-plus";
import {useRouter} from "vue-router";
import axios from "axios";

const registerform = reactive({
  username: '',
  password: ''
})

const router = useRouter()

const onRegister = async () => {
  try {
    console.log(registerform)

    // 假设这是你的登录API端点
    axios.post("http://localhost:8090/register/"+registerform.username+"/"+registerform.password+"").then((response) => {
      console.log(response)

      if (response.data == "success") {

        ElMessage.success("注册成功")
        // router.push("/profile")
        // _this.route.path('/main')
      }
      else {
        ElMessage.error("注册失败:用户名重复或者其他原因！！")
      }
    })



  } catch (error) {
    // 请求出错，显示错误信息
    ElMessage.error("请求错误")
  }
}
</script>

<style>
/* 你可以在这里添加全局样式，或者直接在组件样式中覆盖 */
.el-button {
  height: 40px; /* 假设这是输入框的高度 */
}
</style>
